import requests


class SendRequests(object):
    """
    封装接口的请求
    """

    def __int__(self):
        pass

    def get(self, url, data, header):
        """
        封装 Get 请求
        :param url: 地址
        :param data: 参数
        :param header: 请求头
        :return:
        """
        if header is None:
            res = requests.get(url=url, params=data)
        else:
            res = requests.get(url=url, params=data, headers=header)
        return res.json()

    def post(self, url, data, header):
        """
        封装 Post 亲够
        :param url: 地址
        :param data: 参数
        :param header: 请求头
        :return:
        """
        if header is None:
            # TODO verify = False 忽略证书校验
            res = requests.post(url, data, verify=False)
        else:
            res = requests.post(url, data, headers=header, verify=False)
        return res.json()

    def put(self):
        pass

    def delete(self):
        pass

    def run_main(self, url, data, header, method):
        """
        接口请求主函数
        :param url: 地址
        :param data: 参数
        :param header: 请求头
        :param method: 请求的方法
        :return:
        """
        res = None
        if method.upper() == 'GET':
            res = self.get(url, data, header)
        elif method.upper() == 'POST':
            res = self.post(url, data, header)
        else:
            print('暂时不支持')
        return res


if __name__ == '__main__':
    url = 'http://127.0.0.1:8787/dar/user/login'
    data = {
        "user_name": "test01",
        "passwd": "admin123"
    }

    header = None
    method = 'post'

    send = SendRequests()
    res = send.run_main(url=url, data=data, header=header, method=method)

    print(res)
